/**
 * CS 200 Colorado State University, Fall 2012
 * This is the testing class for PA4. 
 * DO NOT MODYFY main(). Grading will be based on main() of this class.
 */
public class PA4_Test{
    public static void main(String [] args){
	if ((args.length<3)&&(args[0].compareTo("freq")==0)){
	    System.out.println("Please enter your arguments.");
	    System.out.println("e.g. java PA4_Test [command][input file][word]");
	}else if (args.length<2){
	    System.out.println("Please enter your arguments.");
	    System.out.println("e.g. java PA4_Test [command][input file]");
	}else{	    
	    
	    String cmd = args[0];
	    String input = args[1]; 
	    // This command will generate a histogram with your input file specified 
	    // in args[1]
	    if (cmd.compareTo("histogram")==0){
	    	long begin = System.currentTimeMillis();
      		Histogram hg = new Histogram(input);
		long end = System.currentTimeMillis();
		hg.printHistogram();
		System.out.println("Turnaround time for building a hashtable: "+(end-begin)+" milliseconds.");	

		// This command will retrieve the frerquency of specified word in args[2] 
		// from the histogram generated for the book specified in args[1]
	    }else if (cmd.compareTo("freq")==0){
       		Histogram hg = new Histogram(input);
	    	long begin = System.currentTimeMillis();
		int freq = hg.getFrequency(args[2]);
		long end = System.currentTimeMillis();
		System.out.println(args[2] +" has appeared in "+input+" "+freq+" times.");  
		System.out.println("Turnaround time for retrieving data: "+(end-begin)+" milliseconds."); 				

		// This command will retireve the most frequently appeared word(s) from the book 
		// specified in args[1]
	    }else if (cmd.compareTo("mostfreq")==0){
		Histogram hg = new Histogram(input);
	    	long begin = System.currentTimeMillis();
		String [] mostfreq = hg.getMostFrequentWord();
		long end = System.currentTimeMillis();
		for (int i = 0; i < mostfreq.length; i++){
		    System.out.println("Most frequently appreared word(s) is(are) "+mostfreq[i]);
		}	    
		System.out.println("Turnaround time for finding most frequently appeared word : "+(end-begin)+" milliseconds.");	

		// This command will retrieve the number of entities listed in your
		// histogram based on the book specified in args[1]
	    }else if (cmd.compareTo("wordcount")==0){
		Histogram hg = new Histogram(input);
	    	long begin = System.currentTimeMillis();
		int wordcount = hg.getWordCount();
		long end = System.currentTimeMillis();
		System.out.println("There are "+wordcount+" valid word(s)");
		System.out.println("Turnaround time for finding the word count: "+(end-begin)+" milliseconds.");	

	    }
	}
    }



    

}